package wangwenjun.phase3.executor.completablefuture.demo01;

import lombok.extern.slf4j.Slf4j;
import util.ThreadUtil;

import java.util.concurrent.ThreadLocalRandom;

/**
 * @author ChangLiang
 * @date 2020/6/23
 */
@Slf4j
public class DbService {

    public static void insertReportTable1(Object obj) {
        int value = ThreadLocalRandom.current().nextInt(10);
        ThreadUtil.sleepForSeconds(value);
        log.info("insert report table1, time consumption:{} seconds", value);
    }

    public static void insertReportTable2(Object obj) {
        int value = ThreadLocalRandom.current().nextInt(10);
        ThreadUtil.sleepForSeconds(value);
        log.info("insert report table2, time consumption:{} seconds", value);
    }

    public static boolean insertUserTable(Object obj) {
        int value = ThreadLocalRandom.current().nextInt(10);
        ThreadUtil.sleepForSeconds(value);
        log.info("insert user table, time consumption:{} seconds", value);
        int i = 1 / 0;
        return true;
    }

    public static boolean insertDeviceTable(Object obj) {
        int value = ThreadLocalRandom.current().nextInt(10);
        ThreadUtil.sleepForSeconds(value);
        log.info("insert device table, time consumption:{} seconds", value);
//        int i = 1/0;
        return true;
    }

    public static UserObject queryUserWithMobile(String mobile) {
        int value = ThreadLocalRandom.current().nextInt(10);
        ThreadUtil.sleepForSeconds(value);
        log.info("query user table by mobile:{}, time consumption:{} seconds", mobile, value);
//        int i = 1 / 0;
        UserObject userObject = new UserObject();
        userObject.setName("cl");
        userObject.setMobile(mobile);
        return userObject;
    }

    public static DeviceObject queryDeviceWithMobile(String mobile) {
        int value = ThreadLocalRandom.current().nextInt(10);
        ThreadUtil.sleepForSeconds(value);
        log.info("query device table by mobile:{}, time consumption:{} seconds", mobile, value);
        DeviceObject deviceObject = new DeviceObject();
        deviceObject.setDeviceNo("xxxxooooo");
        deviceObject.setMobile("13233333333");
        return deviceObject;
    }
}
